<?php

global $cjdb,$supplier_id;

$p = isset($_MGPC_POST['p']) ? intval($_MGPC_POST['p']) : 1;
$keyword = isset($_MGPC_POST['keyword']) ? htmlspecialchars($_MGPC_POST['keyword']) : "";
$pagemum = 10;
$start = ($p - 1) * $pagemum;
if($supplier_id)$supplierwhere = getsupplierwhere();
$sql = "WHERE module='3' $supplierwhere and lang='cn'";// 商家条件
if($keyword){
    $sql .=" AND post_title like '%".$keyword."%'";
}

$count = mysqli_num_rows($cjdb->query("select id from fastxcms_portal_post_product ".$sql.""));
if($count == 0){
    echo -1;exit;
}
$query = $cjdb->query("select * from fastxcms_portal_post_product ".$sql." order by id desc limit $start,$pagemum");
while ($row = mysqli_fetch_array($query)) {
    $lists[] = array(
        'title' => "<a href='/article/" . $row['id'] . ".html' target='_blank'>" . $row['post_title'] . "</a>",
        'id' => $row['id'],
        'date' => date('m-d H:i', $row['published_time'])
    );
}

$page_html = getGoodsPageHtml($p, $count, 15);
?>

<table width="100%" class="table_parameters" id="table_parameters">
    <tbody>
        <tr class="tr_head">
            <th width="80"><label><input type="checkbox" class="checkbox_all" autocomplete="off"/> ID</label></th>
            <th>标题</td>
            <th width="150">日期</td>
        </tr>
        <?php foreach ($lists as $v) { ?>
            <tr>
                <td><input type="checkbox" class="checkbox_one" value="<?php echo $v['id']; ?>" autocomplete="off"/> <?php echo $v['id']; ?></td>
                <td><?php echo $v['title']; ?></td>
                <td><?php echo $v['date']; ?></td>
            </tr>
        <?php } ?>
    </tbody>
</table>
<div class='searchpager'><?php echo $page_html; ?></div>


<?php

function getGoodsPageHtml($current, $count, $page_row) {
    $page_total = ceil($count / $page_row);
    if ($page_total > 1) {
        $page_html = "" . $count . " 条记录 " . $current . "/" . $page_total . " 页";

        if ($current > 1) {
            $page_html .="<a onclick=getPage(" . ($current - 1) . ") href='javascript:void(0)'>上一页</a>";
        }
        if ($page_total > $current) {
            $page_html .="<a onclick='getPage(" . ($current + 1) . ")'href='javascript:void(0)'>下一页</a>";
        }
        if ($current > 5) {
            $page_html .="<a onclick='getPage(1)' href='javascript:void(0)'>第一页</a>";
        }
        for ($i = 1; $i <= $page_total; $i++) {
            if ($current == $i) {
                $page_html .= "<a class='current' onclick='getPage(" . $i . ")' href='javascript:void(0)'>" . $i . "</a>";
            } else {
                $page_html .= "<a onclick='getPage(" . $i . ")' href='javascript:void(0)'>" . $i . "</a>";
            }
        }
        $page_html .="<a onclick='getPage(" . $page_total . ")' href='javascript:void(0)'>最后一页</a>";
    } else {
        $page_html = "" . $count . " 条记录";
    }
    return $page_html;
}
?>